function buildCouponDiv(coupon) {
    var couponDiv = $("<div class='coupon-block'>");
    couponDiv.attr("c_id",coupon.id);

    var couponTitleLine = $("<div class='coupon-title-line'>");

    var nameSpan = $("<span class='name'>");
    nameSpan.text(coupon.type.name);

    var discountDiv = $("<div class='discount'>");
    var numberSpan = $("<span class='number'>");
    var numberMinSpan = $("<span class='number-min'>");

    if(coupon.type.name == "折扣券") {
        var z =Math.floor(coupon.discount * 10);
        var min = parseInt(coupon.discount * 100) - (Math.floor(coupon.discount * 10) * 10);

        discountDiv.append(numberSpan);
        numberSpan.text(z);
        if(min != 0) {
            numberMinSpan.text(min);
            discountDiv.append(numberMinSpan);
        }

        var offSign = $("<span class='off-sign'>");
        offSign.text("折");


        discountDiv.append(offSign);
    } else if(coupon.type.name == "现金券"){
        numberSpan.text((coupon.discount/100).toFixed(2));

        var moneySign = $("<span class='money-sign'>");
        moneySign.text("¥");

        discountDiv.append(moneySign);
        discountDiv.append(numberSpan);
    }
    couponTitleLine.append(nameSpan);
    couponTitleLine.append(discountDiv);


    var expireLine = $("<div class='expire-line'>");

    var expireSpan = $("<span class='expire'>");


    if(coupon.end_time != null) {
        var date = new Date(coupon.end_time);
        expireSpan.text(date.format("yyyy年MM月dd日")+"到期");
        expireLine.append(expireSpan);
    } else {
        //TODO 自领用开始有效期XX天
    }






    var descriptionLine = $("<div class='description-line'>");

    var descriptionSpan = $("<span class='description'>");
    descriptionSpan.text(coupon.description);

    descriptionLine.append(descriptionSpan);
    if(coupon.reduce_condition.min_amount != null) {
        var amountSpan = $("<span class='amount'>");
        amountSpan.text("满"+(coupon.reduce_condition.min_amount/100)+"元可享受");
        descriptionLine.append(amountSpan);
    }


    couponDiv.append(couponTitleLine);
    couponDiv.append(expireLine);
    couponDiv.append(descriptionLine);

    return couponDiv;
}

function checkCoupon(coupon,medicalStaffId,type,amount,cityId) {
    var nowTime = new Date().getTime();

    if (coupon.reduce_condition.min_amount != null && amount < (coupon.reduce_condition.min_amount)) {
        return false;
    }
    if (coupon.reduce_condition.srv_type != null) {
        if (coupon.reduce_condition.srv_type instanceof Array) {
            var hasType = false;
            $.each(coupon.reduce_condition.srv_type, function (idx, srvType) {
                if (srvType == type) {
                    hasType = true;
                }
            });
            if (!hasType) {
                return false;
            }
        } else {
            if (coupon.reduce_condition.srv_type != type) {
                return false;
            }
        }
    }
    if (coupon.reduce_condition.city != null) {
        if (coupon.reduce_condition.city instanceof Array) {
            var hasCity = false;
            $.each(coupon.reduce_condition.city, function (idx, city) {
                if (city == parseInt(cityId)) {
                    hasCity = true;
                }
            });
            if (!hasCity) {
                return false;
            }
        } else {
            if (coupon.reduce_condition.city != parseInt(cityId)) {
                return false;
            }
        }
    }
    if(coupon.start_time != null && nowTime < coupon.start_time) {
        return false;
    }
    if(coupon.end_time != null && nowTime > coupon.end_time) {
        return false;
    }


    return true;
}